package com.example.springboot.controller;

import com.example.springboot.entity.ForumPostLike;
import com.example.springboot.service.ForumPostLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/likes")
public class ForumPostLikeController {

    @Autowired
    private ForumPostLikeService forumPostLikeService;

    @PostMapping
    public void likePost(@RequestBody ForumPostLike like) {
        forumPostLikeService.likePost(like);
    }

    @DeleteMapping("/{postId}/{userId}")
    public void unlikePost(@PathVariable Integer postId, @PathVariable Integer userId) {
        forumPostLikeService.unlikePost(postId, userId);
    }

    @GetMapping("/{postId}/{userId}")
    public boolean isPostLikedByUser(@PathVariable Integer postId, @PathVariable Integer userId) {
        return forumPostLikeService.isPostLikedByUser(postId, userId);
    }
    // 新增接口：根据用户 ID 获取点赞列表
    @GetMapping("/user/{userId}")
    public List<ForumPostLike> getLikesByUserId(@PathVariable Integer userId) {
        return forumPostLikeService.getLikesByUserId(userId);
    }
}